package com.firewolf.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.AMQP.BasicProperties;

import utils.ConnectionUtils;

public class Receiver {
	private static final String QUEUE_NAME = "queue_confirmqueue_serial";

	public static void main(String[] args) throws Exception{
		Connection connection = ConnectionUtils.getMQConnection();

		final Channel channel = connection.createChannel();

	    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		Consumer consumer = new DefaultConsumer(channel) {
			public void handleDelivery(String consumerTag, com.rabbitmq.client.Envelope envelope,
					BasicProperties properties, byte[] body) throws java.io.IOException {
				try {
					String msg = new String(body);
					System.out.println("Receiver:" + msg);
				} catch (Exception e) {
					e.printStackTrace();
				}finally {
					channel.basicAck(envelope.getDeliveryTag(), false);
				}			
			};
		};
		
		channel.basicConsume(QUEUE_NAME,false, consumer);
		
	}
}
